/**
 * 维修 整改  投诉的点检异常资料
 */
import React from 'react'
import { Table } from 'antd'
import './index.styl'
import TitleLine from 'components/common/titleLine'
import repairCn from 'columns/deviceRepair'
import Voice from 'components/common/voice'
import Picture from 'components/common/picture'
import { randomString } from 'utils/format'

function EquipmentCheckError({ data }) {
  // 状态
  const statusStr = (key) => {
    switch (Number(key)) {
      case 1:
        return '未开始';
      case 2:
        return '进行中';
      case 2:
        return '已完成';
      case 4:
        return '超时完成';
      default:
        return '——'
    }
  }

  // 添加序号
  repairCn.checkError[0].render = (t, r, i) => `${i+1}`
  // 任务执行时间
  repairCn.checkError[2].render = (t) => <span>{t ? t : '——'}</span>
  // 状态
  repairCn.checkError[3].render = (t, r) => <span>{statusStr(r.status)}</span>
  // 执行结果
  repairCn.checkError[4].render = (t, r) => (
    <>
      <span>
        { Number(r.result) === 1 ? '成功' : null}
        { Number(r.result) === -1 ? '——' : null}
        {
        Number(r.result) === 0
        ?
        `失败${r.failReason ? `：${r.failReason}` : ''}`
        :
        null
        }
      </span>
    </>
  )

  // 获取图片名称
  const getPictureName = (name) => {
    if (name) {
      let nameArr = name.split('/')
      return nameArr[nameArr.length - 1]
    }
    return 'picture'
  }

  // 添加操作
  repairCn.checkError[repairCn.checkError.length -2].render = (t, r) => (
    <>
      {
        r.images ?
        <>
          <Picture imgUrl={r.images} name={getPictureName(r.images)}/>
        </>
        :
        '——'
      }

    </>
  )
   // 添加操作
  repairCn.checkError[repairCn.checkError.length -1].render = (t, r) => (
    <>
      {
        r.voices
        ?
        <Voice voiceUrl={r.voices}/>
        :
        '——'
      }
    </>
  )

  const { orderCheckerror } = data ? data : { orderCheckerror: [] }

  return (
    <div className='EquipmentCheckErrorBox'>
      <TitleLine title='点检异常资料' />
      <Table
        columns={repairCn.checkError}
        dataSource={orderCheckerror}
        pagination={false}
        bordered={true}
        className="self-table"
        rowKey={() => randomString()}
      />
    </div>
  )
}

export default EquipmentCheckError

